package com.kevin.jdk8;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {
    public static void main(String[] args) {
        final ArrayList<A> aList = new ArrayList<A>();
        aList.add(new A("zhangsan"));
        aList.add(new A("lisi"));
        ArrayList<B> bList = new ArrayList<B>();

//        aList.stream().forEach(m->{
//            B b = new B();
//            b.setName(m.getNum());
//            bList.add(b);
//        });

//        aList.stream().map(m->{
//            B b = new B();
//            b.setName(m.getNum());
//            bList.add(b);
//            return bList;
//        }).collect(Collectors.toList());

        aList.stream().peek(m->{
            B b = new B();
            b.setName(m.getNum());
            bList.add(b);
        }).collect(Collectors.toList());

        List<String> collect = Stream.of("gabg").peek(m -> m.replace("a", "c")).collect(Collectors.toList());
        System.out.println(collect);

        System.out.println(bList);
    }
}

class A {
    private String num;

    public A(String num) {
        this.num = num;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }
}

class B {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "B{" +
                "name='" + name + '\'' +
                '}';
    }
}
